import Vue from 'vue'
import VueI18n from 'vue-i18n'
import Cookies from 'js-cookie'

import elementEnLocale from 'element-ui/lib/locale/lang/en' // element-ui lang
import elementZhLocale from 'element-ui/lib/locale/lang/zh-CN'// element-ui lang
//错误信息资源
import enCommonErr from './errorCode/en/common'
import zhCommonErr from './errorCode/zh/common'
import enLoginErr from './errorCode/en/login'
import zhLoginErr from './errorCode/zh/login'
//界面元素资源
import enLogin from './view/en/login'
import zhLogin from './view/zh/login'
import enMaps from './view/en/maps'
import zhMaps from './view/zh/maps'
import enCommon from './view/en/common'
import zhCommon from './view/zh/common'

Vue.use(VueI18n);

const messages = {
    en: {
        ...enCommonErr,
        ...enLoginErr,

        ...enCommon,
        ...enLogin,
        ...enMaps,
        ...elementEnLocale
    },
    zh: {
        ...zhCommonErr,
        ...zhLoginErr,

        ...zhCommon,
        ...zhLogin,
        ...zhMaps,
        ...elementZhLocale
    }
};

const i18n = new VueI18n({
    locale: Cookies.get('language') || 'zh', // set locale
    messages // set locale messages
});

export default i18n;
